/*
 *  This file is part of "SchoolChoice",
 *  a school registration system.
 *
 *  Copyright (C) 2009 Nicolas Decerf, Olivier Jacquemin.
 *
 *  "SchoolChoice" is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  "SchoolChoice" is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program: see the file COPYING.txt.  If not, see
 *  http://www.gnu.org/licenses/.
 */

/*
 * SchoolEditor class.
 */

/*global SchoolChoice */

(function() {
     // Private static data.

     // Shortcut notation.
     var WAC = SchoolChoice.WebAppClient;

     // Private static methods.


     // Class and constructor declaration.
     WAC.SchoolEditor = function() {
         this._url = "schooleditor.html";
     };

     // SchoolEditor inherits from View.
     WAC.SchoolEditor.prototype = new WAC.View();

     /*
      * Displays a School object for edition.
      */
     WAC.SchoolEditor.prototype.setSchool = function(school) {
         if (!school) {
             school = new WAC.School();
         }
         $("#SchoolEditorName").val(school.id);
         $("#SchoolEditorAddress").val(school.streetAndNumber);
         $("#SchoolEditorPostalCode").val(school.postalCode);
         $("#SchoolEditorCity").val(school.city);
         $("#SchoolEditorSeats").val(school.availableSeats + ""); // Explicit conversion to string.
     };

     /*
      * Returns a School object corresponding to the edition fields.
      */
     WAC.SchoolEditor.prototype.getSchool = function() {
         var school = new WAC.School();
         school.id = $("#SchoolEditorName").val();
         school.streetAndNumber = $("#SchoolEditorAddress").val();
         school.postalCode =  $("#SchoolEditorPostalCode").val();
         school.city =  $("#SchoolEditorCity").val();
         school.availableSeats =  ($("#SchoolEditorSeats").val() - 0); // Explicit conversion to number.

         return school;
     };

     // Public static methods
 }) ();
